
define(['jquery'], () => {
    const rap2 = 'http://rap2api.taobao.org/app/mock/232089'
    const baseUrl = 'http://www.xmyxapp.com/api'
    const php = '/api'
    return {
        //主页三个广告位
        thr_adver() {
            return new Promise(resolve => {
                $.get(`${rap2}/index/thr_adver`, resolve)
            })
        },

        //主页8个广告位
        adverrender() {
            return new Promise(resolve => {
                $.get(`${rap2}/index/get`, resolve)
            })
        },

        //列表页渲染商品
        list_get(id, start, sort) {
            if(!id) id = 1
            return new Promise(resolve => {
                $.get(`${baseUrl}/tab/${id}?start=${start}&sort=${sort}`, resolve)
            })
        },

        //获取详细数据
        getDetail(id) {
            return new Promise(resolve => {
                $.get(`${baseUrl}/detail`, {id}, resolve)
            })
        },


        //登录
        login( userInfo) {
            return new Promise(resolve => {
                // $.get(`/libs/json/users.json`, null, resolve)
                
                // $.get('http://localhost/api/v1/users/login.php', userInfo, resolve)
                let url = `http://localhost/api/v1/users/login.php?`
                if (userInfo) {
                    for (var key in userInfo) {
                        url += `&${key}=${userInfo[key]}`
                    }
                }
                $.post(url, userInfo, resolve)
            })
        },

        //注册
        register(userInfo) {
            return new Promise(resolve => {
                // $.get(`/libs/json/users.json`, null, resolve)
                
                // $.get('http://localhost/api/v1/users/login.php', userInfo, resolve)
                let url = `http://localhost/api/v1/users/register.php?`
                if (userInfo) {
                    for (var key in userInfo) {
                        url += `&${key}=${userInfo[key]}`
                    }
                }
                $.post(url, userInfo, resolve)
            })
        }
    }
}
);